using DevFramework.Entities.Concrete;
using FluentNHibernate.Mapping;

namespace DevFramework.DataLayer.Concrete.NHibernate.Mapping
{
    public partial class OrderMap : ClassMap<Order>
    {
        public OrderMap()
        {
              Table(@"Orders");

              LazyLoad();

              Id(x => x.OrderId)
                .Column("OrderID")
                .CustomType("Int32")
                .Access.Property()
                .CustomSqlType("int")
                .Not.Nullable()
                .Precision(10)                
                .GeneratedBy.Identity();

              Map(x => x.CustomerId)    
                .Column("CustomerID")
                .CustomType("String")
                .Access.Property()
                .Generated.Never()
                .CustomSqlType("nchar")
                .Length(5);

              Map(x => x.OrderDate)    
                .Column("OrderDate")
                .CustomType("DateTime")
                .Access.Property()
                .Generated.Never()
                .CustomSqlType("datetime");

              Map(x => x.RequiredDate)    
                .Column("RequiredDate")
                .CustomType("DateTime")
                .Access.Property()
                .Generated.Never()
                .CustomSqlType("datetime");

              Map(x => x.ShippedDate)    
                .Column("ShippedDate")
                .CustomType("DateTime")
                .Access.Property()
                .Generated.Never()
                .CustomSqlType("datetime");

              Map(x => x.Freight)    
                .Column("Freight")
                .CustomType("Decimal")
                .Access.Property()
                .Generated.Never()
                .Default(@"0")
                .CustomSqlType("money")
                .Precision(19)
                .Scale(4);

              Map(x => x.ShipName)    
                .Column("ShipName")
                .CustomType("String")
                .Access.Property()
                .Generated.Never()
                .CustomSqlType("nvarchar")
                .Length(40);

              Map(x => x.ShipAddress)    
                .Column("ShipAddress")
                .CustomType("String")
                .Access.Property()
                .Generated.Never()
                .CustomSqlType("nvarchar")
                .Length(60);

              Map(x => x.ShipCity)    
                .Column("ShipCity")
                .CustomType("String")
                .Access.Property()
                .Generated.Never()
                .CustomSqlType("nvarchar")
                .Length(15);

              Map(x => x.ShipRegion)    
                .Column("ShipRegion")
                .CustomType("String")
                .Access.Property()
                .Generated.Never()
                .CustomSqlType("nvarchar")
                .Length(15);

              Map(x => x.ShipPostalCode)    
                .Column("ShipPostalCode")
                .CustomType("String")
                .Access.Property()
                .Generated.Never()
                .CustomSqlType("nvarchar")
                .Length(10);

              Map(x => x.ShipCountry)    
                .Column("ShipCountry")
                .CustomType("String")
                .Access.Property()
                .Generated.Never()
                .CustomSqlType("nvarchar")
                .Length(15);

              //HasMany(x => x.OrderDetails)
              //  .Access.Property()
              //  .AsSet()
              //  .Cascade.None()
              //  .LazyLoad()
              //    // .OptimisticLock.Version() /*bug (or missing feature) in Fluent NHibernate*/
              //  .Inverse()
              //  .Generic()
              //  .KeyColumns.Add("OrderID", mapping => mapping.Name("OrderID")
              //                                                       .SqlType("int")
              //                                                       .Not.Nullable());

              //References(x => x.Customer)
              //  .Class<Customer>()
              //  .Access.Property()
              //  .Cascade.None()
              //  .LazyLoad()
              //  .Columns("CustomerID");
        }
    }
}
